package com.prs.crm.domain.flow;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

import com.prs.crm.domain.hr.Dept;
import com.prs.crm.domain.hr.Person;
import com.prs.crm.domain.hr.Role;

/**
 * 流程责任人
 * @author Administrator
 *
 */
@Embeddable
public class WorkFlowHandler implements java.io.Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@ManyToOne
	private Person principal;
	
	@ManyToMany(fetch=FetchType.LAZY)
	private Set<Person> executors = new HashSet<Person>();
	@ManyToOne(fetch=FetchType.LAZY)
	private Role role;
	@ManyToOne(fetch=FetchType.LAZY)
	private Dept dept;
	
	public WorkFlowHandler()
	{
		
	}
	public WorkFlowHandler(Dept dept,Role role)
	{
		setDept(dept);
		setRole(role);
	}
	public void setExecutors(Set<Person> executors) {
		this.executors = executors;
	}

	public Set<Person> getExecutors() {
		return executors;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public Role getRole() {
		return role;
	}

	public void setDept(Dept dept) {
		this.dept = dept;
	}

	public Dept getDept() {
		return dept;
	}
	public void setPrincipal(Person principal) {
		this.principal = principal;
	}
	public Person getPrincipal() {
		return principal;
	}
	
	
	public void addExecutors(Collection<Person> executors)
	{
		if (executors!=null)
		{
			this.getExecutors().addAll(executors);
		}
	}
	
	
	public void copyFrom(WorkFlowHandler handler)
	{
		this.setDept(handler.getDept());
		this.setRole(handler.getRole());
		this.setPrincipal(handler.getPrincipal());
		this.getExecutors().clear();
		this.getExecutors().addAll(handler.getExecutors());
	}
	
}
